package com.ruoyi.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.product.domain.SysBrand;
import com.ruoyi.product.service.ISysBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 品牌管理Controller
 *
 * @author tsh
 * @date 2025-08-02
 */
@RestController
@RequestMapping("/brand")
public class SysBrandController extends BaseController {
    @Autowired
    private ISysBrandService sysBrandService;
    @Autowired
    HttpServletRequest request;


//    /**
//     * 查询品牌管理列表
//     */
//    @RequiresPermissions("product:brand:list")
//    @GetMapping("/list")
//    public TableDataInfo list(SysBrand sysBrand)
//    {
//        startPage();
//        List<SysBrand> list = sysBrandService.selectSysBrandList(sysBrand);
//        return getDataTable(list);
//    }

    /**
     * 查询品牌管理列表
     */
    @RequiresPermissions("product:brand:list")
    @GetMapping("/list")
    public TableDataInfo list(SysBrand sysBrand) {
        String pageNum = request.getParameter("pageNum");
        String pageSize = request.getParameter("pageSize");
        return sysBrandService.getBrandList(sysBrand, Integer.valueOf(pageNum), Integer.valueOf(pageSize));
    }

    /**
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @description 获取品牌所有列表
     * @params
     * @author tsh
     * @date 2025/8/5 18:51
     */
    @RequiresPermissions("product:brand:list")
    @GetMapping("/getBrandListAll")
    public AjaxResult getBrandListAll() {
        return sysBrandService.getBrandListAll();
    }


    /**
     * 导出品牌管理列表
     */
    @RequiresPermissions("product:brand:export")
    @Log(title = "品牌管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBrand sysBrand) {
        List<SysBrand> list = sysBrandService.selectSysBrandList(sysBrand);
        ExcelUtil<SysBrand> util = new ExcelUtil<SysBrand>(SysBrand.class);
        util.exportExcel(response, list, "品牌管理数据");
    }

    /**
     * 获取品牌管理详细信息
     */
    @RequiresPermissions("product:brand:query")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Integer brandId) {
        return success(sysBrandService.selectSysBrandByBrandId(brandId));
    }

    /**
     * 新增品牌管理
     */
    @RequiresPermissions("product:brand:add")
    @Log(title = "品牌管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBrand sysBrand) {
        return toAjax(sysBrandService.insertSysBrand(sysBrand));
    }

    /**
     * 修改品牌管理
     */
    @RequiresPermissions("product:brand:edit")
    @Log(title = "品牌管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBrand sysBrand) {
        return toAjax(sysBrandService.updateSysBrand(sysBrand));
    }

    /**
     * 删除品牌管理
     */
    @RequiresPermissions("product:brand:remove")
    @Log(title = "品牌管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{brandIds}")
    public AjaxResult remove(@PathVariable Integer[] brandIds) {
        return toAjax(sysBrandService.deleteSysBrandByBrandIds(brandIds));
    }

}
